//  导航菜单映射数组
var mainNavmap = [{
    "name": "信用查询",
    "value": "verify",
    "child": [{
        "name": "Step 1 选择组合",
        "value": "verify1",
        "iclass": "icon-dashboard"
    }, {
        "name": "Step 2 采集信息",
        "value": "verify2",
        "iclass": "icon-edit"
    }, {
        "name": "Step 3 查看结果",
        "value": "verify3",
        "iclass": "icon-tint"
    }]
}, {
    "name": "查询历史",
    "value": "query",
    "child": [{
        "name": "当天查询记录",
        "value": "intraday",
        "iclass": "icon-calendar-empty"
    }, {
        "name": "条件查询记录",
        "value": "history",
        "iclass": "icon-calendar"
    }]
}, {
    "name": "查询组合管理",
    "value": "combination",
    "child": [{
        "name": "现有组合",
        "value": "existing",
        "iclass": "icon-cogs"
    }/*, {
        "name": "组合设定",
        "value": "setup",
        "iclass": "icon-legal"
    }*/]
}, {
    "name": "帐务管理",
    "value": "accounts",
    "child": [{
        "name": "计次管理",
        "value": "timesCount",
        "iclass": "icon-pencil"
    }/*, {
        "name": "计费管理",
        "value": "charging",
        "iclass": "icon-pencil"
    }, {
        "name": "帐号余额",
        "value": "balance",
        "iclass": "icon-money"

    }*/]
}, {
    "name": "用户管理",
    "value": "users",
    "child": [/*{
        "name": "机构管理",
        "value": "mechanism",
        "iclass": "icon-group"
    },*/ {
        "name": "用户管理",
        "value": "staff",
        "iclass": "icon-user"
    }]
}, {
    "name": "修改密码",
    "value": "changepassword",
    "child": [{
        "name": "修改密码",
        "value": "timesCount",
        "iclass": "icon-pencil"
    }]
}];


/*// 后台取得权限数据
var power = {
    "verify": "all",
    "query": "all",
    "combination": "all",
    "accounts": "all",
    "users": "all"
};
*/
// 根据后台数据取导航栏数据
function getNavData(power) {  // 传参数power
    var navData = [];
    var mainPower = ["verify", "query", "combination", "accounts", "users"];
    for (var i = 0, l = mainNavmap.length; i < l; i++) {
        if (power[mainNavmap[i].value]) {
            var theNavData = mainNavmap[i];
            if (power[mainNavmap[i].value] != "all") {
                var thechild = [];
                for (var n = 0, m = mainNavmap[i].child.length; n < m; n++) {
                    if (power[mainNavmap[i].value].search(mainNavmap[i].child[n].value) != -1) {
                        thechild.push(mainNavmap[i].child[n]);
                    }
                }
                theNavData.child = thechild;
            }
            navData.push(theNavData);
        }
    }
    return navData;
}

// 退出清空cookie数据
function singout() {
    $.removeCookie("name");
    $.removeCookie('password');
    
    location.href = "./index.html";
}

module.exports = {
    getNavData: getNavData,
    mainNavmap: mainNavmap,
    singout: singout
}